package com.mf.basic.services;

import com.mf.basic.entity.DtoApiLog;
import com.mf.basic.mapper.MapperApiLog;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by Luke on 2025/3/19 20:32.
 */
@Service
public class ServiceApiLog extends ServiceImpl<MapperApiLog, DtoApiLog> implements BaseService<DtoApiLog>{

    @Override
    public LambdaQueryWrapper<DtoApiLog> fillParams(Map<String, Object> params) {
        LambdaQueryWrapper<DtoApiLog> qw = loadQw();
        Object tmp = params.get("douser");
        qw.eq(paramNotNull(tmp), DtoApiLog::getDouser, tmp);
        tmp = params.get("startTime");
        if(paramNotNull(tmp)){
            String startTime = tmp.toString();
            tmp = params.get("endTime");
            if(paramNotNull(tmp)){
                String endTime = tmp.toString();
                qw.between(DtoApiLog::getDotime, startTime, endTime);
            }else{
                qw.ge(DtoApiLog::getDotime, startTime);
            }
        }
        tmp = params.get("operation");
        qw.like(paramNotNull(tmp), DtoApiLog::getOperation, tmp);
        tmp = params.get("params");
        qw.like(paramNotNull(tmp), DtoApiLog::getParams, tmp);
        qw.orderByDesc(DtoApiLog::getId);
        return qw;
    }
}
